<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>忘记密码 - 个人博客系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" href="../../static/layui/css/admin.css" media="all" th:href="@{/layui/css/admin.css}">
    <link rel="stylesheet" href="../../static/layui/css/login.css" media="all" th:href="@{/layui/css/login.css}">
</head>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-forget" style="display: none;">
        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>找回密码</h2>
                <h5>第二步：输入激活码和新密码</h5>
                <font style="color: red"></font>
            </div>
                <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                    <input type="hidden" name="email" th:value="${email}">
                    <div class="layui-form-item">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                               for="LAY-user-login-password"></label>
                        <input type="password" name="password" id="LAY-user-login-password"
                               placeholder="请输入新密码" class="layui-input">
                        <div id="password_check"></div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-row">
                            <div class="layui-col-xs7">
                                <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                                       for="LAY-user-login-vercode"></label>
                                <input type="text" name="vercode" id="LAY-user-login-vercode"
                                       placeholder="验证码" class="layui-input">
                            </div>
                            <div class="layui-col-xs5">
                                <div style="margin-left: 10px;">
                                    <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid"
                                            id="LAY-user-getsmscode">验证码为6位
                                    </button>
                                </div>
                            </div>
                            <div id="code_check"></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <button id="submit" class="layui-btn layui-btn-fluid" lay-submit
                                lay-filter="LAY-user-reg-submit">提交</button>
                    </div>
                </div>
        </div>


    </div>


</div>
<script src="../../static/layui/layui.js" th:src="@{/layui/layui.js}"></script>
<script src="../../static/js/jquery-1.8.3.min.js" th:src="@{/js/jquery-1.8.3.min.js}"></script>
<script type="text/javascript" th:inline="javascript">

    $(function () {
        if (/*[[${msg}]]*/null != null){
            alert(/*[[${msg}]]*/);
        }
    });

    function checkPassword() {
        var pattern = /^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,20}$/;
        var password = $("#LAY-user-login-password").val();
        var flag = pattern.test(password);
        if (!flag) {
            //不合法
            $("#password_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                '                            style="color: red;">请输入6-20位数字,字母,特殊字符中两种组合</span>')
        } else {
            //合法
            $("#password_check").html('<i style="color: green" class="layui-icon layui-icon-ok"></i><span\n' +
                '                            style="color: green;">密码格式正确</span>');
        }

        return flag;
    }

    function checkCode() {
        var pattern = /^[a-zA-Z0-9]{6}$/;
        var code = $("#LAY-user-login-vercode").val();
        var flag = pattern.test(code);
        if (!flag) {
            //不合法
            $("#code_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                '                            style="color: red;">请输入6位包含数字或字母的验证码</span>')
        } else {
            //合法
            $("#code_check").html('<i style="color: green" class="layui-icon layui-icon-ok"></i><span\n' +
                '                            style="color: green;">验证码格式正确</span>');
        }

        return flag;
    }

    $("#LAY-user-login-password").blur(checkPassword);
    $("#LAY-user-login-vercode").blur(checkCode);

    layui.use(['form', 'jquery','layer'], function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var $ = layui.jquery;
        var layer = layui.layer;
        form.on('submit(LAY-user-reg-submit)', function (data) {
            var c2 = checkPassword();
            var c3 = checkCode();
            if (c2 && c3) {
                $.post(/*[[@{/user/forget/update}]]*/"/user/forget/update", data.field, function (data) {
                    if (data.flag) {
                        if (confirm(data.success_message)) {
                            location.href = /*[[@{/user/login}]]*/"/user/login";
                        }
                    } else {
                        layer.msg(data.fail_message);
                    }
                });
            }
        });
    });
</script>
<script>


    layui.use('form', function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

        //……

        //但是，如果你的HTML是动态生成的，自动渲染就会失效
        //因此你需要在相应的地方，执行下述方法来手动渲染，跟这类似的还有 element.init();
        form.render();//在最后添加这句代码
    });


</script>
</body>
</html>